package com.dzm.xgb.core.controller.admin;

import com.dzm.common.exception.Assert;
import com.dzm.common.result.R;
import com.dzm.common.result.ResponseEnum;
import com.dzm.xgb.core.pojo.entity.IntegralGrade;
import com.dzm.xgb.core.service.IntegralGradeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 作者：Dzm
 * 时间：2024-08-27-11:52
 * 功能：
 */

@RestController
@RequestMapping("/admin/core/integralGrade")
@Api(tags = "积分等级接口")
public class AdminIntegralGradeController {

    @Autowired
    private IntegralGradeService integralGradeService;

    @GetMapping("/list")
    @ApiOperation("积分等级列表")
    public R list() {
        List<IntegralGrade> list = integralGradeService.list();
        return R.ok().data("list", list);
    }

    @GetMapping("/getById/{id}")
    @ApiOperation("根据id获取积分等级")
    public R getById(@PathVariable("id") Integer id) {
        IntegralGrade integralGrade = integralGradeService.getById(id);

        return R.ok().data("integralGrade", integralGrade);
    }

    @PostMapping("/save")
    @ApiOperation("添加积分等级")
    public R saveIntegralGrade(@RequestBody IntegralGrade integralGrade) {
        Assert.notNull(integralGrade.getBorrowAmount(), ResponseEnum.BORROW_AMOUNT_NULL_ERROR);
        integralGradeService.save(integralGrade);

        return R.ok();
    }

    @PutMapping("/update")
    @ApiOperation("修改积分等级")
    public R updateIntegralGrade(@RequestBody IntegralGrade integralGrade) {
        Assert.notNull(integralGrade.getBorrowAmount(), ResponseEnum.BORROW_AMOUNT_NULL_ERROR);
        integralGradeService.updateById(integralGrade);

        return R.ok();
    }

    @DeleteMapping("/remove/{id}")
    @ApiOperation("根据id删除积分等级")
    public R removeById(@PathVariable("id") Integer id) {
        integralGradeService.removeById(id);

        return R.ok();
    }

}
